{template header}
<script src="static/bootstrap/js/utils.js"></script>
<script src="static/js/js.js"></script>
<link rel="stylesheet" href="static/calendar/js/calendar.css" />
<script type="text/javascript" charset="utf-8" src="static/calendar/calendar.php"></script>
<link rel="stylesheet" href="static/kindeditor/themes/default/default.css" />
<script charset="utf-8" src="static/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="static/kindeditor/lang/zh_CN.js"></script>
<style type="text/css">
  .boardDiv{margin-bottom: 10px;}
  .boardList{margin: 10px auto;}
  .boardList li{list-style-type:none;float:left;margin:2px 9px;background-color:#dbeaf9;padding:5px;cursor:pointer;border-radius: 8px;}
  .boardList label{float: left;margin-bottom: 0;}
  .boardList label input {float: left;margin-right: 5px;}
  .tagList{margin: 10px auto;}
  .tagList li{list-style-type:none;float:left;margin:2px 9px;background-color:#dbeaf9;padding:5px;cursor:pointer;border-radius: 8px;}
  .tagList label{float: left;margin-bottom: 0;}
  .tagList label input {float: left;margin-right: 5px;}
  #content_view {position:absolute; left:0px; top:0px; width:100%; height:100%; display:none;}
  #content_view_bg {position:absolute; left:0px; top:0px; width:100%; height:100%; background-color:#999; opacity:0.3; filter:alpha(opacity=30);}
  #ipbg {position:absolute; width:260px; height:529px; background-image:url("/static/images/ipbg.png"); background-size:100%; background-repeat:no-repeat;}
  #content_view_tab {position:absolute; width:260px; text-align: center;}
  .view_tab {color:#333;}
  #ipbg .content{margin:65px 15px 0 15px; padding: 10px; width:210px; height:380px; overflow:scroll; background-color:#fff; font-size:12px;}
  #ipbg .content .list {border:solid 1px #eee; border-radius:5px; padding:5px;}
  #ipbg .content .title {font-weight:bold; font-size:14px;}
  #ipbg .content .day, #ipbg .content .author {color:#999;}
  #ipbg .content .desc {margin-top:8px; line-height:18px;}

    .ke-icon-card {
        width: 16px;
        height: 16px;
        background-size: 100% 100%;
        background-image:url("/static/images/icon/ke_icon_gear.png");
    }
  .ke-icon-tao {
    width: 16px;
    height: 16px;
    background-size: 100% 100%;
    background-image:url("/static/images/icon/ke_icon_tao.png");
  }
    .gearList {
        height: 400px;
        overflow: scroll;
    }
    #search li{height:220px;width:170px;overflow: hidden; float:left; text-align: center;}
    #search img {width:100px;height:100px;}
    widget {color:;}

</style>
<script type="text/html" id="gearListTemp">
<ul class="thumbnails" id="search">
  <% for(var i=0;i<data.length;i++){%>
  <li class="span3 card" data-index="<%=i%>">
    
      <img src="<%=data[i].pic%>" alt="">
      <p>
        <%if(data[i].type=='groupon'){%>
          【推荐】
        <%}%>
        <%=data[i].title%>
      </p>
      <p style="color:red"><%=data[i].price%></p>
     
  </li>
  <%}%>
</ul>
</script>
<script charset="utf-8" src="static/js/admincard.js"></script>
<script  type="text/javascript">
  function upload_frame_load() {
    var data = $(window.frames['upload_frame'].document.body).html();
    if(data) {
      data = eval('(' + data + ')');
      if(data.status=='ok'){
        $('#taopic').attr('src',data.image);
      }else{
        alert(data.error_msg);
      }
    }
  }
</script>
<form id="pic_form" method="post" target="upload_frame" action="/index.php?c=ajax&a=AdminUploadChannelPic" enctype="multipart/form-data">
  <input type="file" name="picFile" id="picFile" style="display:none;" onchange="$('#pic_form').submit();">
  <input type="hidden" id="picChannelId" name="picChannelId" value="0">
  <input type="hidden" id="picChannelPrice" name="picChannelPrice" value="0">
</form>
<iframe id="upload_frame" name="upload_frame" style="display:none" onLoad="upload_frame_load();"></iframe>

<script type="text/javascript">

    window.onload=function (){
        var a_channel = $("#a_channel").val();
        if(a_channel != ''){
            $("input#start_time_btn").attr("disabled", false);
            $("input#end_time_btn").attr("disabled", false);
        }else{
            $("input#start_time_btn").attr("disabled", true);
            $("input#end_time_btn").attr("disabled", true);
        }
  }
  $(document).ready(function(){
      $("select#a_channel").blur(function()
        {
          var a_channel = $(this).val();
          if(a_channel != ''){
            $("input#start_time_btn").attr("disabled", false);
            $("input#end_time_btn").attr("disabled", false);
        }else{
            $("input#start_time_btn").attr("disabled", true);
            $("input#end_time_btn").attr("disabled", true);
        }
        });
      $("ul#boardList input").click(function(e){       
          var boardId = $(this).val();
          var isChecked = $(this).prop("checked");
          
          if(boardId=='gearEval'){
            if(isChecked) {
              $('#rungearInputGear').show();
            } else {
              $('#rungearInputGear').hide();
            }
          }

          if(isChecked == false){
            return true;
          }

          $.ajax({url:"index.php?c=admin&a=addPostBoard&boardId=" + boardId,
                  async:false,
                  dataType:"json",
                  error:function(){
                      alert('未知错误');
                      },
                  success:function(data, status){
                    turnData = eval(data);
                    if(turnData.message == ''){
                        for(var i=0; i<turnData.tagList.length; i ++){
                          tagId = turnData.tagList[i].tagId;
                          tagName = turnData.tagList[i].tagName;
                          if($("li#litag_"+tagId).html() == undefined){
                            var newLi = "<li id='litag_"+tagId+"'><label for='tag_"+tagId+"'><input type='checkbox' id='tag_"+tagId+"' value='"+tagId+"' name='tagId[]'>"+tagName+"</label></li>";
                            $("#tagList").append(newLi);
                          }
                        }
                    }
                    else
                    {
                      //alert(turnData.message);
                    }
                    $("input#newTag").toggleClass("hide");
                    $("span#subNewTag").toggleClass("hide");
                  }
              });
          return true;
      });
      $("input#authorId").blur(function(e){
          var uid = $(this).val();
          if(uid == '' || uid == 0){
            //alert('请输入帖子作者id');
            return false;
          }
          $.ajax({url:"index.php?c=admin&a=checkVipUser&uid=" + uid+"&type=1",
            async:false,
            dataType:"json",
            error:function(){
                alert('未知错误');
                },
            success:function(data, status){
              turnData = eval(data);
              if(!Utils.isEmpty(turnData.message))
              {
                  $("#uid").val('');
                  alert(turnData.message);
              }
              else{
                nickname = turnData.nickname;
                header = turnData.header;
                $("#authorId").siblings("img").prop("src",header);
                $("#authorId").siblings("span").text(nickname);
              }
            }
        });
        return;
      });
      $("ul#tagList input").click(function(e){
          var tid = $(this).val();
          if($(this).prop("checked") == true){
            var num = 0;
            $("ul#tagList input").each(function(){
                if($(this).prop("checked") == true) num +=1;
                if(num > 3) {
                  alert('最多选择3个标签');
                  $("input#tag_"+tid).prop("checked", false);
                  return false;
                }
            });
          }
      });
    });


</script>
<style type="text/css">
  label{float: left;margin: auto 10px;}
</style>
<form class="form-horizontal" action="index.php?c=admin&a=postInfo&gid={$gid}" method="post" enctype="multipart/form-data">
{if $groupInfo}
  <div class="control-group">
      <label class="control-label" for="inputTiltle">群组：</label>
      <div class="controls">
        <span class="label label-info" style="font-size:14px;">{$groupInfo['name']}</span>
      </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputShortDesc">群组中置顶：</label>
    <div class="controls">
      <select name="is_top" class="input-mini">
        <option value="1">是</option>
        <option {if empty($postInfo['is_top']) || $postInfo['is_top'] == 0} selected="selected" {/if} value="0">否</option>
      </select>
    </div>
  </div>
{/if}
  <div class="control-group">
    <label class="control-label" for="inputTiltle">标题：</label>
    <div class="controls">
      <input type="text" name='title' placeholder="请输入标题" value="{$postInfo['title']}">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputShortDesc">帖子简介：</label>
    <div class="controls">
      <textarea name="short_desc" placeholder="请输入帖子简介" style="min-width:80%; min-height:200x;">{$postInfo['short_desc']}</textarea>
        <code style="color:red;">*简介内容请截取部分帖子内容，用于客户端展示</code>
    </div>

  </div>
  <div class="control-group">
    <label class="control-label" for="inputShortDesc">是否显示：</label>
    <div class="controls">
      <select name="is_show">
        <option value="1">是</option>
        <option {if $postInfo['is_show'] == 0} selected="selected" {/if} value="0">否</option>
      </select>
    </div>
  </div>
  {loop $postInfo['thumb_img'] $k $img}
  <div class="control-group">
    <label class="control-label" for="inputThumbImg">缩略图：</label>
    <div class="controls">
      {if $img}
      <img width="50" src="{$img}" alt="缩略图"> <code style="color:#999"><a href="{eval echo $postInfo['sourceImg'][$k]}">大图链接</a>（右击，选"链接另存为"即可下载大图）</code>
      {/if}
      <!-- <input type="file" name="thumb_img_{$k}"> -->
    </div>
  </div>
  {/loop}
  <div class="control-group  pr">
    <label class="control-label" for="inputauthor">作者：</label>
    <div class="controls">
      <img width="50" src="{$postInfo['header']}" alt="作者头像">
      <span>{$postInfo['nickname']}</span>

      
      <input type="text" name="uid" placeholder="请输入帖子作者id" value="{$postInfo['uid']}" id="authorId">
    </div>
  
  </div>
  {if !$groupInfo}
  <div class="control-group">
    <label class="control-label" for="inputstarttime">开始显示时间：</label>
    <div class="controls">
      <input type="text" name="start_time" readonly="readonly" id="starttimeid" value="{eval echo date('Y-m-d H:i:s', $postInfo['start_time'])}">
      <input name="starttimebtn" type="button" id="starttimebtn" onclick="return showCalendar('starttimeid', '%Y-%m-%d %H:%M:%S', '24', false, 'starttimebtn');" value="选择" class="button" />
      <input type="button" class="button" value="归零" id="resetStartTime">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputtag">运营渠道：</label>
    <div class="controls">
      <select name="a_channel" id="a_channel">
        <option value="">非渠道运营文章</option>
        {loop $channelList $k $channel}
          <option value="{$k}" {if $postInfo['a_channel'] == $k} selected="seleted"{/if}>{$channel}</option>
        {/loop}
      </select>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputaddtime">设置活动期限：</label>
    <div class="controls">
      开始时间：<input type="text" name="a_start_time" readonly="readonly" id="start_time_id" value="{eval echo date('Y-m-d H:i', $postInfo['a_start_time'])}">
      <input name="start_time_btn" type="button" id="start_time_btn" onclick="return showCalendar('start_time_id', '%Y-%m-%d %H:%M', '24', false, 'start_time_btn');" value="选择" class="button" id="start_time_id"/>
      结束时间：<input type="text" name="a_end_time" readonly="readonly" id="end_time_id" value="{eval echo date('Y-m-d H:i', $postInfo['a_end_time'])}">
      <input name="end_time_btn" type="button" id="end_time_btn" onclick="return showCalendar('end_time_id', '%Y-%m-%d %H:%M', '24', false, 'end_time_btn');" value="选择" class="button" id="end_time_id"/>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputaddtime">设置添加时间：</label>
    <div class="controls">
      <input type="text" name="add_time" readonly="readonly" id="add_time_id" value="{eval echo date('Y-m-d H:i:s', $postInfo['add_time'])}">
      <input name="add_time_btn" type="button" id="add_time_btn" onclick="return showCalendar('add_time_id', '%Y-%m-%d %H:%M:%S', '24', false, 'add_time_btn');" value="选择" class="button" id="add_time_id"/>
    </div>
  </div>
  {/if}
  <div class="control-group">
    <label class="control-label">
      帖子内容：<font color="blue"><br>如有图片<br>图片宽度<br>不应小于<br><strong>640px</strong><br></font>
    </label>
    <div class="controls">
        <textarea id="content" name="content" style="width:800px;height:400px;">{$postInfo['content']}</textarea>
        <div style="margin-top:10px;"><span class="draft label"></span> <code class="draft_re" style="display:none"><a id="re_content" href="javascript::;">恢复最后一次保存内容</a></code></div>

    </div>
  </div>
  {if !$groupInfo}
  <!--<div class="control-group">
    <label class="control-label" for="inputauthor">1.0资讯：</label>
    <div class="controls">
      <label for="is_yd_yes"><input type="radio" name="is_yd" value="1" id="is_top_yes" {if $postInfo['is_yd'] == 1} checked="checked"{/if}> 是</label>
      <label for="is_td_no"><input type="radio" name="is_yd" value="0" id="is_top_no" {if $postInfo['is_yd'] != 1} checked="checked"{/if}> 否</label>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputauthor">1.0标签：</label>
    <div class="controls">
      <input type="text" name='otag' placeholder="请输入标签" value="{$postInfo['otag']}">
    </div>
  </div>-->
  <div class="control-group">
    <label class="control-label" for="inputtag">版块：</label>
    <div class="controls boardDiv">
      <ul id="boardList" class="boardList">
        {loop $boardList $k $v}
          <li><label for="{$v['boardId']}"><input type="checkbox" name="boardId[]" value="$v['boardId']" id="{$v['boardId']}" {if $v['isMem'] == '1'}checked="checked" {/if}>{$v['boardName']}</label></li>
        {/loop}
      </ul>
    </div>
  </div>
  <div class="control-group" id='rungearInputGear' style="display:none">
    <div class="controls">
    请选择目标装备id<input name='togearid'/><span id='resgaerid' style='color:red'>* 装备评测必填</span>
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputtag">标签：</label>
    <div class="controls">
      <ul class="tagList" id="tagList">
          {loop $tagList $k $tag}
           <li id="litag_{$tag['tagId']}">
            <label for="tag_{$tag['tagId']}">
              <input type="checkbox" name="tagId[]" value="$tag['tagId']" id="tag_{$tag['tagId']}" {if $tag['isMem'] == '1'}checked="checked"{/if}>{$tag['tagName']}
            </label>
          </li>
          {/loop}
      </ul>
    </div>
  </div>
  {/if}
  <div class="control-group">
    <div class="controls">
        <input type="hidden" name="postId" value="{$postInfo['postId']}">
        {if $action == 'add'}
          <input type="hidden" name="action" value="insert">
        {elseif $action == 'edit'}
          <input type="hidden" name="action" value="update">
        {/if}
        <button type="submit" class="btn">提交</button>
        <button id="view" type="button" class="btn btn-success">预览（仅供参考）</button>
        <a class="btn btn-edit" href="?c=admin&a=delPost&newsid=$postInfo['postId']" onclick="return confirm('Are you sure?')">删除</a>
    </div>
  </div>
</form>

<div id="content_view">
    <div id="content_view_bg"></div>
    <div id="ipbg">
        <div class="content"></div>
    </div>
    <div id="content_view_tab">
        <code class="view_tab to_list"><a href="javascript:;">列表预览</a></code>
        <code class="view_tab to_content"><a href="javascript:;">内容预览</a></code>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $('#view').bind('click', function(){
            var top = $(document).scrollTop() + 10;
            var left = $(document).width() / 2 - $('#ipbg').width() / 2;
            $('#ipbg').attr({'style': 'top:' + top + 'px; left: ' + left + 'px;'});
            $('#content_view_tab').attr({'style': 'top:' + (top + $('#ipbg').height() + 5) + 'px; left:' + left + 'px;'});
            $('#content_view').attr({'style': 'height:' + $(document).height() + 'px;'}).show();
            content_view_list();
            return false;
        });

        $('#content_view_bg').bind('click', function(){
            $('#content_view').hide();
        });

        $('#content_view_tab .to_list').bind('click', function(){
            content_view_list();
        });

        $('#content_view_tab .to_content').bind('click', function(){
            content_view_list(1);
        });

        function content_view_list(type) {
            type = type ? 1 : 0;

            var title = $('input[name="title"]').val();
            var content = editor.html();
            var author = $('.pr .controls span').text();
            author = author ? author : '扑妞';
            var d = new Date();
            var day1 = d.getFullYear() + "-" +(d.getMonth()+1) + "-" + d.getDate();
            var day2 = d.getFullYear() + "年" +(d.getMonth()+1) + "月" + d.getDate() + '日';
            var desc = content.replace(/<[^>]+>/g, '');
            desc = desc.length > 100 ? desc.substr(0, 100) : desc;
            var img = content.match(/<img(.+?)src=""*([^\s]+?)""*(\s|>)/ig);

            var html;

            if(!type) {
                html = '<div class="list"><div class="title">'+title+'</div><div class="day">'+day2+'</div><div class="desc">'+desc+'</div>' + (img ? '<div class="img">'+img+'"</div>' : '') + '</div>';
            } else {
                html = '<div class="info"><div class="title">'+title+'</div><div class="box"><span class="day">'+day1+'</span> &nbsp; <span class="author">'+author+'</span></div><div class="text">'+content+'</div></div>';
            }

            $('#content_view #ipbg .content').html(html);
        }
    });


    function getgear(thisgearid){

    $.ajax({
      url:'/adminajax/hasThisGear',
      data:{id:thisgearid},
      dataType:'json',
      success:function(res){
        if(res.msg){
          $('#resgaerid').html(res.msg)
           $('#resgaerid').attr('style',"color:red");
        }else{
          var reshtml=res.data.name+"<img width='200px' src='"+res.data.images[0]+"' />";
           $('#resgaerid').html(reshtml)
           $('#resgaerid').attr('style',"color:green")
        }
      }
    })  

}
//只有跑步装备时弹出，如果选择跑步装备帖子必须选择目标装备
$('[name=togearid]').on('blur',function(){
     thisgearid=this.value;
      getgear(thisgearid)
  })
  //编辑页面默认评测装备展开
  var gid= {if empty($postInfo['gid'])}null{else}$postInfo['gid']{/if};
  if(gid){
    $('#rungearInputGear').show();
    $('[name=togearid]').val(gid)
    getgear(gid)
  }
    // 草稿箱
    var is_draft = window.localStorage;

    if(!is_draft) {
        $('.draft').text('当前浏览器不支持草稿箱功能');
    } else if(is_draft) {
        if(localStorage.thread_content) {
            $('.draft').text('发现草稿箱中有上次保存内容，可以恢复至 ' + localStorage.thread_last_save_time);
            $('.draft_re').show();
        } else {
            $('.draft').text('30秒后，当前内容将会自动保存至草稿箱');
        }

        function save_content() {
            var d = new Date();
            var time = d.getFullYear() + "-" +(d.getMonth()+1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

            var content = editor.html();
            var old_content = '';

            if(content) {
                if(content != old_content) {
                    localStorage.thread_content = content;
                    localStorage.thread_last_save_time = time;
                    old_content = content;
                }

                $('.draft').text('最后一次自动保存于: ' + time);
                $('.draft_re').show();
            }
        }

        $(function(){
            $('#re_content').on('click', function(){
                editor.html(localStorage.thread_content);
                $('.draft').text('已恢复至: ' + localStorage.thread_last_save_time);
                return false;
            });
            $('.postform').on('click', function(){
                //localStorage.removeItem('thread_content');
                //localStorage.removeItem('thread_last_save_time');
            });
        });

        setInterval("save_content()", 30000);
    }

 
</script>


{template footer}